<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <p id="p1" draggable="true">元素</p>
    <p id="target" ondrop="drop_handler(event)" ondragover="dragover_handler(event)">
        Drop Zone
    </p>
    <script>
        const handleDragStart = (e) => {
            console.log("e: ", e)
            e.dataTransfer.dropEffect = "copy";
            e.dataTransfer.setData('text/plain', e.target.id)
        }

        window.addEventListener("DOMContentLoaded", () => {
            const element = document.getElementById('p1');
            element.addEventListener('dragstart', handleDragStart)
        })

        function dragover_handler(ev) {
            ev.preventDefault();
            ev.dataTransfer.dropEffect = "copy";
        }
        function drop_handler(ev) {
            ev.preventDefault();
            // Get the id of the target and add the moved element to the target's DOM
            var data = ev.dataTransfer.getData("text/plain");
            ev.target.appendChild(document.getElementById(data));
        }
    </script>
</body>

</html>